def send():
    print("发送消息")


def outer(fn):  # 装饰器
    # 既包含原有功能，又包含新功能
    def inner():
        print("登录...")
        fn()
        print("注销...")
    return inner


@outer
def send2():
    print("转账520")


def outer_with_params(fn):
    def inner(name):
        print(f"{name}是inner函数中的参数")
        print("哈哈")
        fn(name)
    return inner


@outer_with_params
def send3(name):
    print("转账1314")


def outer_variable_params(fn):
    def inner(*args, **kwargs):
        print("I am OK")
        fn(*args, **kwargs)
    return inner


@outer_variable_params
def send4(*args, **kwargs):
    print(args)
    print(kwargs)


def decorator1(fn):
    def inner():
        return "d1" + fn()
    return inner


def decorator2(fn):
    def inner():
        return "d2" + fn()
    return inner


@decorator1
@decorator2
def send5():
    return "6"


if __name__ == "__main__":
    ot = outer(send)
    ot()

    send2()
    print("====================")
    send3("wtf")
    print("====================")
    send4(1, "2", name="bingbing", age=18)
    print("====================")
    print(send5())  # 多个装饰器，离函数最近的先执行
